package com.anyou.mall.enterprise.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.common.core.domain.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.AjaxResult;
import com.anyou.common.enums.BusinessType;
import com.anyou.mall.enterprise.domain.EnterpriseType;
import com.anyou.mall.enterprise.service.IEnterpriseTypeService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 企业类型Controller
 *
 * @author 李奇鹏
 * @date 2022-03-08
 */
@Api(tags = "企业类型")
@RestController
@RequestMapping("/enterprise/enterprise")
public class EnterpriseTypeController extends BaseController
{
    @Autowired
    private IEnterpriseTypeService enterpriseTypeService;

    /**
     * 查询企业类型列表
     */
    @ApiOperation("查询企业类型列表")
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnterpriseType enterpriseType)
    {
        startPage();
        List<EnterpriseType> list = enterpriseTypeService.selectEnterpriseTypeList(enterpriseType);
        return getDataTable(list);
    }

    /**
     * 导出企业类型列表
     */
    @ApiOperation("导出企业类型列表")
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:export')")
    @Log(title = "企业类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EnterpriseType enterpriseType)
    {
        List<EnterpriseType> list = enterpriseTypeService.selectEnterpriseTypeList(enterpriseType);
        ExcelUtil<EnterpriseType> util = new ExcelUtil<EnterpriseType>(EnterpriseType.class);
        util.exportExcel(response, list, "企业类型数据");
    }

    /**
     * 获取企业类型详细信息
     */
    @ApiOperation("获取企业类型详细信息")
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:query')")
    @GetMapping(value = "/{enterpriseTypeId}")
    public ApiResult getInfo(@PathVariable("enterpriseTypeId") Long enterpriseTypeId)
    {
        return ApiResult.success(enterpriseTypeService.selectEnterpriseTypeByEnterpriseTypeId(enterpriseTypeId));
    }

    /**
     * 新增企业类型
     */
    @ApiOperation("新增企业类型")
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:add')")
    @Log(title = "企业类型", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody EnterpriseType enterpriseType)
    {
        return ApiResult.success(enterpriseTypeService.insertEnterpriseType(enterpriseType));
    }

    /**
     * 修改企业类型
     */
    @ApiOperation("修改企业类型")
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:edit')")
    @Log(title = "企业类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody EnterpriseType enterpriseType)
    {
        return ApiResult.success(enterpriseTypeService.updateEnterpriseType(enterpriseType));
    }

    /**
     * 删除企业类型
     */
    @ApiOperation("删除企业类型")
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:remove')")
    @Log(title = "企业类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{enterpriseTypeIds}")
    public ApiResult remove(@PathVariable Long[] enterpriseTypeIds)
    {
        return ApiResult.success(enterpriseTypeService.deleteEnterpriseTypeByEnterpriseTypeIds(enterpriseTypeIds));
    }

    /**
     * 获取企业类型列表
     */
    @ApiOperation("获取企业类型列表")
    @PreAuthorize("@ss.hasPermi('enterprise:enterprise:alllist')")
    @GetMapping("/allList")
    public ApiResult<List<EnterpriseType>> getAllList() {
        return enterpriseTypeService.getAllList();
    }
}
